﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.Windows.Media.Animation;

namespace VODCopyRighter
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            progressBar.Visibility = Visibility.Hidden;
            msg3.IsEnabled = false;

            DoubleAnimation animation = new DoubleAnimation();
            Duration duration = new Duration(TimeSpan.FromSeconds(20));
            DoubleAnimation doubleanimation = new DoubleAnimation(200.0, duration);
            cameraImage.BeginAnimation(, doubleanimation);
            cameraImage.Margin = new Thickness(cameraImage.Margin.Left,cameraImage.Margin.Top,cameraImage.Margin.Right,cameraImage.Margin.Bottom);  
          
        }

        private void browseButton_1_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.ShowDialog();
            this.inputTextBox_1.Text = openFileDialog1.FileName;
        }

        private void convert_1_Click(object sender, RoutedEventArgs e)
        {
            if (this.inputTextBox_1.Text.Trim().Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("you must choose avi file to add watermark");
                return;
            }

            if (this.outputTextBox_1.Text.Trim().Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("you must choose a file name to save in");
                return;
            }

            if (this.passTextBox_1.Text.Trim().Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("you must choose a password");
                return;
            }

            if (this.msgTextBox_1.Text.Trim().Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("you should enter a message to add");
                return;
            }

            MOSEC_Video.addLSBtoAVI(inputTextBox_1.Text, outputTextBox_1.Text, msgTextBox_1.Text, passTextBox_1.Text);

            System.Windows.Forms.MessageBox.Show("finished");
        }

        private void convert_3_Click(object sender, RoutedEventArgs e)
        {
            progressBar.Visibility = Visibility.Visible;
            Duration duration = new Duration(TimeSpan.FromSeconds(20));
            DoubleAnimation doubleanimation = new DoubleAnimation(200.0, duration);
           

            if (this.input3.Text.Trim().Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("you must choose avi file to extract watermark");
                return;
            }

            if (this.pass3.Text.Trim().Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("you must write the passord");
                return;
            }
            try
            {
                progressBar.BeginAnimation(System.Windows.Controls.ProgressBar.ValueProperty, doubleanimation);
                msg3.Text = MOSEC_Video.extractMsgFromAVI(input3.Text, pass3.Text);
            }
            catch (Exception ee)
            {
                System.Windows.Forms.MessageBox.Show(ee.Message);
            }
        }

        private void convert_2_Click(object sender, RoutedEventArgs e)
        {
            if (this.inputfiles.Text.Trim().Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("you must choose avi file to add watermark");
                return;
            }

            if (this.outputname.Text.Trim().Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("you must choose a file name to save in");
                return;
            }

            if (this.password2.Text.Trim().Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("you must choose a password");
                return;
            }

            if (this.message2.Text.Trim().Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("you should enter a message to add");
                return;
            }

            char[] chars = Environment.NewLine.ToCharArray();
            string[] lines = inputfiles.Text.Split(chars);
            
            MOSEC_Video.generateAVIwithLSBfromPhotos(outputname.Text, message2.Text, password2.Text, lines, new int[lines.Length]);

            System.Windows.Forms.MessageBox.Show("finished");
        }

        private void browseButton_2_Click(object sender, RoutedEventArgs e)
        {
            char[] chars = Environment.NewLine.ToCharArray();
            string[] lines = inputfiles.Text.Split(chars);

            OpenFileDialog openFileDialog2 = new OpenFileDialog();
            openFileDialog2.ShowDialog();
            string[] f = openFileDialog2.FileNames;
            List<string> l = new List<string>();
            l.AddRange(f);
            l.AddRange(lines);

            string newLines = "";

            foreach ( string X in l.ToArray())
            {
                newLines+= X;
                newLines+= chars[0];
            }

            inputfiles.Text = newLines;

        }

        private void browseButton_3_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.ShowDialog();
            this.input3.Text = openFileDialog1.FileName;
        }

        private void helpButton_Click(object sender, RoutedEventArgs e)
        {
            VideoPreview form = new VideoPreview();
            form.ShowDialog();
        }
    }
}
